<?php

namespace App\Models;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Laravel\Lumen\Auth\Authorizable;
use Laravel\Passport\HasApiTokens;

class User extends BaseModel implements AuthenticatableContract, AuthorizableContract
{

    //用户验证attempt
    use Authenticatable, Authorizable;
    use HasApiTokens, SoftDeletes;


    protected $table = 'users';
    protected $maps = [
//        'job_title' => 'jobtitle'
    ];

    const STATUS_OK = 1;
    const STATUS_FREEZE = 0;

    const STATUS_TEXTS = [
        self::STATUS_OK => '正常',
        self::STATUS_FREEZE => '禁用',
    ];

    public function getStatusText()
    {
        $map = self::STATUS_TEXTS;
        return $map[$this->status] ?? $this->status;
    }

    public function department(){
        return $this->belongsTo(Department::class);
    }

    public function absences(){
        return $this->hasMany(Absence::class);
    }

    public function transportations(){
        return $this->hasMany(Transportation::class);
    }

    public function egresses(){
        return $this->hasMany(Egress::class);
    }


}
